<template>
	<view class="container">
	  <view class="example">
	    <uni-forms ref="form" :model="pigPregnancyList" labelWidth="80px">
	      <uni-forms-item label="猪只耳号" name="pigCode">
	        <uni-easyinput v-model="pigPregnancyList.pigCode" placeholder="请输入猪只耳号" />
	      </uni-forms-item>

		<uni-forms-item label="妊检管理员" name="pregnancyTestManager" required>
			<!-- 下拉框选择 -->
			<uni-data-select
					v-model="pigPregnancyList.pregnancyTestManager"
					:localdata="staffNameList"
					@change="change">
			</uni-data-select>
		</uni-forms-item>

		<uni-forms-item label="妊检方式" name="pregnancyTestType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigPregnancyList.pregnancyTestType"
			 :localdata="pregnancyTestTypes"
			 @change="change">
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="妊检结果" name="pregnancyTestResult" required>
						<!-- 下拉框选择 -->
						<uni-data-select
						 v-model="pigPregnancyList.pregnancyTestResult"
						 :localdata="pregnancyTestResults"
						 @change="change">
						 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="栏舍类型" name="phouseType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="pigPregnancyList.phouseType"
			 :localdata="phouseTypes"
			 @change="change">
			 </uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="妊娠天数" name="pregnancyDays">
		  <uni-easyinput v-model="pigPregnancyList.pregnancyDays" placeholder="请输入妊娠天数" />
		</uni-forms-item>

		<view class="example-body">
			<uni-forms-item label="妊检时间" name="pregnancyTime">
			  <uni-datetime-picker type="datetime" v-model="pigPregnancyList.pregnancyTime" @change="changeLog" />
			</uni-forms-item>
			</view>
		<uni-forms-item label="备注">
			<uni-easyinput type="textarea" v-model="pigPregnancyList.remark" placeholder="请输入备注内容" />
		</uni-forms-item>
	    </uni-forms>

	    <button type="primary" @click="submit">提交</button>
	  </view>
	</view>
</template>

<script>



import {  addPigPregnancy,findAllStaffName, updatePigPregnancy, delPigPregnancy} from "@/api/hmy/pigPregnancy";
export default {

  name: "PigPregnancy",
  // dicts: ['hmy_pig_out_type','hmy_park_type','hmy_pig_type'],
  data() {
   return {
	   pigPregnancyList: {
   				pigCode: "",
				pregnancyTestManagers:"",
		  	 	pregnancyTestTypes:"",
		   		pregnancyTestResult:"",
   				phouseTypes: "",
		   		pregnancyDays:"",
		   		pregnancyTime:"",
   				remark:""
   			},
   			phouseTypes: [{
   			  text: ' 公猪舍',
   			  value: "1"
   			},
   			{
   			  text: ' 母猪舍',
   			  value: "2"
   			},
   			{
   			  text: ' 肉猪舍',
   			  value: "3"
   			}
   			],
		 	pregnancyTestTypes:[{
				text: ' 外部观察法',
				value: "1"
			},{
				text: '直肠触诊法',
				value: "2"
			},{
				text: ' 超声波诊断法',
				value: "3"
			},{
				text: '激素诊断法',
				value: "4"
			}
			],
	   		pregnancyTestResults:[{
   				text: ' 阴性(未怀孕)',
   				value: "1"
   			},{
   				text: ' 阳性(已怀孕)',
   				value: "2"
   			}
   			],
   			rules: {
   			  pigCode: {
   				rules: [{
   				  required: true,
   				  errorMessage: '猪只耳号不能为空'
   				}]
   			  }
   			},
	   //所有猪只配种负责人
	   staffNameList: [],
   		}
   	  },
	created() {

		findAllStaffName().then(response => {
			console.log(response);
			var staffList = response.data;

			staffList.forEach(item => {
				this.staffNameList.push({
					'text': item.staffName,
					'value': item.staffId
				})
			})
			//console.log(this.staffNameList);
		})
	},

   	   methods: {
   	 	  	change(e) {
   	 	  				this.single = e
   	 	  				console.log('change事件:', this.single = e);
   	 	  			},
   	 	  	changeLog(e) {
   	 	  				console.log('change事件:', e);
   	 	  			},
   	     submit(ref) {
   	       this.$refs.form.validate().then(res => {
			   addPigPregnancy(this.pigPregnancyList).then(response => {
   	           this.$modal.msgSuccess("新增成功")
			   //成功后返回页面
			   this.$tab.navigateTo('/pages/hmy/pigPregnancy/index');
   	         })
   	       })
   	     }
   	   }
   	 }
   	 </script>

<style lang="scss">

/* #ifndef APP-NVUE */
page {
 display: flex;
 flex-direction: column;
 box-sizing: border-box;
 min-height: 100%;
 height: auto;
 background-color: #fcfcfc;
}

view {
 font-size: 16px;
 line-height: inherit;
}
/* #endif */
.code{
margin-bottom :5px;
}
.icon{
float:right;
margin-right:10px;
margin-top :5px;
}
.message{
margin-top:5px;
color: #989897;
line-height: 25px;
}


.example {
 padding: 15px;
 background-color: #fff;
}

.segmented-control {
 margin-bottom: 15px;
}

.button-group {
 margin-top: 15px;
 display: flex;
 justify-content: space-around;
}

.form-item {
 display: flex;
 align-items: center;
 flex: 1;
}

.button {
 display: flex;
 align-items: center;
 height: 35px;
 line-height: 35px;
 margin-left: 10px;
}
</style>

